using System.Collections;
using System.Collections.Generic;
using Net.Common;
using UnityEngine;
using UnityEngine.UI;

/****************************************************
// 功能：
// | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
// | Copyright (c) 2021-2025 聊来 All rights reserved.
// | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">聊来</a> )
// | @Author: 贯彻己道的云 <18970881148@qq.com>
// | DateTime: 2025/3/27 15:3:8
*****************************************************/

public partial class PlayerControlWindow
{
    public SkillItem skaItem;
    public SkillItem sk1Item;
    public SkillItem sk2Item;
    public SkillItem sk3Item;

    public Transform imgInfoRoot;
    public Image imgInfoCd;

    private bool showImgInfo;
    private float showTimeCounter;
    private float showTime;
    
    private bool isForbidReleaseSkill;
    
    public void InitSkillInfo()
    {
        Debug.Log("技能初始化");
        var self = model.battleHero[model.currentIndex];
        var heroConfig = resource.GetUnitConfigData(self.heroId);
        var skillArr = heroConfig.skillArr;
        
        skaItem.InitSkillItem(resource.GetSkillConfigById(skillArr[0]), 0);
        sk1Item.InitSkillItem(resource.GetSkillConfigById(skillArr[1]), 1);
        sk2Item.InitSkillItem(resource.GetSkillConfigById(skillArr[2]), 2);
        sk3Item.InitSkillItem(resource.GetSkillConfigById(skillArr[3]), 3);
        
        SetForbidState(false);
        SetActive(imgInfoRoot, false);
    }
    
    public void SetForbidState() {
        SetForbidState(true);
        isForbidReleaseSkill = true;
    }
    
   public void UpdateSkillWnd() {
        if(isForbidReleaseSkill) {
            if(BattleController.Instance.IsForbidSelfPlayerReleaseSkill() == false) {
                SetForbidState(false);
                isForbidReleaseSkill = false;
            }
        }

        if(Input.GetKeyDown(KeyCode.Space)) {
            skaItem.ClickSkillItem();
        }
        else if(Input.GetKeyDown(KeyCode.Alpha1)) {
            sk1Item.ClickSkillItem();
        }
        else if(Input.GetKeyDown(KeyCode.Alpha2)) {
            sk2Item.ClickSkillItem();
        }
        else if(Input.GetKeyDown(KeyCode.Alpha3)) {
            sk3Item.ClickSkillItem();
        }
        
        //
        // if(Input.GetKeyDown(KeyCode.F1)) {
        //    model.currentIndex = 0;
        // }
        // else if(Input.GetKeyDown(KeyCode.F2)) {
        //     model.currentIndex = 1;
        // }
        // else if(Input.GetKeyDown(KeyCode.F3)) {
        //     model.currentIndex = 2;
        // }
        // else if(Input.GetKeyDown(KeyCode.F4)) {
        //     model.currentIndex = 3;
        // }
        // else if(Input.GetKeyDown(KeyCode.F5)) {
        //     model.currentIndex = 4;
        // }
        // else if(Input.GetKeyDown(KeyCode.F6)) {
        //     model.currentIndex = 5;
        // }
   }
    
    private void SetForbidState(bool state)
    {
        sk1Item.SetForbidState(state);
        sk2Item.SetForbidState(state);
        sk3Item.SetForbidState(state);
    }


    public void SetImgInfo(int cdTime) {
        SetActive(imgInfoRoot);
        showImgInfo = true;
        showTimeCounter = 0;
        showTime = cdTime * 1.0f / 1000;
    }
    
    public void UpdateImgInfo(float delta)
    {
        if (!showImgInfo) return;
        showTimeCounter += delta;
        if(showTimeCounter >= showTime) {
            showTimeCounter = 0;
            SetActive(imgInfoRoot, false);
            showImgInfo = false;
        }
        else {
            imgInfoCd.fillAmount = 1 - showTimeCounter / showTime;
        }
    }
}
